Skip to content

BUG: Replaced ValueError exception with TypeError exception in df.where() function #56495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 16, 2024
Merged

BUG: Replaced ValueError exception with TypeError exception in df.where() function #56495

merged 23 commits into from
Jan 16, 2024

Conversation

DarthKitten2130
Copy link
Contributor

@DarthKitten2130 DarthKitten2130 commented Dec 14, 2023

Replaced ValueError exception with TypeError as it is more appropriate for the error it serves

[] closes issue #56330 where there was a consensus that a TypeError is more appropriate for the following error: "Boolean array expected for the condition, not (non-bool type)". Since ValueErrors are raised when the type is correct but the value is incorrect, whereas in this function we are raising an exception because of a wrong type, hence the TypeError.

I've also included commits to update the tests for this method.

(I had already made this PR but messed up my commits because I'm new to GitHub so I'm redoing it).

…function

Replaced ValueError exception with TypeError as it is more appropriate for the error it serves.
@DarthKitten2130 DarthKitten2130 marked this pull request as ready for review December 14, 2023 16:49
@lopof
Copy link
Contributor

lopof commented Dec 15, 2023

@DarthKitten2130
Copy link
Contributor Author

You have to adjust one more test here: https://github.com/pandas-dev/pandas/blob/main/pandas/tests/series/indexing/test_where.py#L204

Thank you so much! Finally passed the checks!

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a whatsnew entry in v2.20.rst?

@mroeschke mroeschke added the Error Reporting Incorrect or improved errors from pandas label Dec 18, 2023
@KetuPatel806
Copy link
Contributor

Can you add a whatsnew entry in v2.20.rst?
@mroeschke I thought you just talking about adding up a new header whasnew will coming up with Updated version.

@@ -896,6 +896,7 @@ Other
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55009`)
- Bug in :meth:`DataFrame.from_dict` which would always sort the rows of the created :class:`DataFrame`. (:issue:`55683`)
- Bug in :meth:`DataFrame.sort_index` when passing ``axis="columns"`` and ``ignore_index=True`` raising a ``ValueError`` (:issue:`56478`)
- Bug in :meth:`DataFrame.where()` where using a non-bool type array in the function would return a ``ValueError`` instead of a ``TypeError`` (:issue:`56330`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this to v3.0.0.rst?

Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment otherwise looks good

@mroeschke mroeschke added this to the 3.0 milestone Jan 16, 2024
@mroeschke mroeschke merged commit 414154f into pandas-dev:main Jan 16, 2024
@mroeschke
Copy link
Member

Thanks @DarthKitten2130

@DarthKitten2130 DarthKitten2130 deleted the 56330 branch January 16, 2024 20:42
pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
…re() function (pandas-dev#56495)

* Replaced ValueError exception with TypeError exception in df.where() function

Replaced ValueError exception with TypeError as it is more appropriate for the error it serves.

* Updated test_where.py to account for updated exceptions.

* Update test_indexing.py to account for modified exceptions

* Update test_where.py for series

* Added bug fix to v2.2.0.rst

* Updated v2.2.0.rst

* Updated v2.2.0.rst

* Updated v2.2.0.rst

* Updated v2.2.0.rst

* Updated v2.2.0.rst

* resolved merge conflict

* resolved conflicts again

* Updated v2.2.0.rst

* Updated v2.2.0.rst

* removed change from 2.20

* Update v2.3.0.rst

* Update doc/source/whatsnew/v2.3.0.rst

Co-authored-by: Matthew Roeschke <[email protected]>

---------

Co-authored-by: Matthew Roeschke <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants